package com.akk.module.yb.model;

import com.akk.PayConstants;
import com.akk.module.yb.utils.Digest;
import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.commons.httpclient.methods.multipart.StringPart;

import java.util.ArrayList;
import java.util.List;

public class WithdrawRequest {
    private String mainCustomerNumber; //代理商商户编号
    private String customerNumber; //商户编号
    private String externalNo; //结算请求号
    private String transferWay; //结算方式
    private String amount; //结算金额
    private String callBackUrl; //结算回调地址
    private String hmac; //签名信息

    public String getMainCustomerNumber() {
        return mainCustomerNumber;
    }

    public void setMainCustomerNumber(String mainCustomerNumber) {
        this.mainCustomerNumber = mainCustomerNumber;
    }

    public String getCustomerNumber() {
        return customerNumber;
    }

    public void setCustomerNumber(String customerNumber) {
        this.customerNumber = customerNumber;
    }

    public String getExternalNo() {
        return externalNo;
    }

    public void setExternalNo(String externalNo) {
        this.externalNo = externalNo;
    }

    public String getTransferWay() {
        return transferWay;
    }

    public void setTransferWay(String transferWay) {
        this.transferWay = transferWay;
    }

    public String getAmount() {
        return amount;
    }

    public void setAmount(String amount) {
        this.amount = amount;
    }

    public String getCallBackUrl() {
        return callBackUrl;
    }

    public void setCallBackUrl(String callBackUrl) {
        this.callBackUrl = callBackUrl;
    }

    public String getHmac() {
        return hmac;
    }

    public void setHmac(String hmac) {
        this.hmac = hmac;
    }

    public static String signature(WithdrawRequest request) {
        StringBuffer sb = new StringBuffer();
        sb.append(request.getAmount() == null?"":request.getAmount());
        sb.append(request.getCustomerNumber() == null?"":request.getCustomerNumber());
        sb.append(request.getExternalNo() == null?"":request.getExternalNo());
        sb.append(request.getMainCustomerNumber() == null?"":request.getMainCustomerNumber());
        sb.append(request.getTransferWay() == null? "":request.getTransferWay());
        sb.append(request.getCallBackUrl() == null?"":request.getCallBackUrl());
        return Digest.hmacSign(sb.toString(), PayConstants.YB_PARAMS_HMAC_KEY);
    }

    public static Part[] builderPart(WithdrawRequest request) {
        List<Part> parts = new ArrayList<Part>();
        parts.add(new StringPart("mainCustomerNumber",request.getMainCustomerNumber()==null?"":request.getMainCustomerNumber(),"UTF-8"));
        parts.add(new StringPart("amount",request.getAmount()==null?"":request.getAmount(),"UTF-8"));
        parts.add(new StringPart("callBackUrl",request.getCallBackUrl()==null?"":request.getCallBackUrl(),"UTF-8"));
        parts.add(new StringPart("customerNumber",request.getCustomerNumber()==null?"":request.getCustomerNumber(),"UTF-8"));
        parts.add(new StringPart("hmac",request.getHmac() == null ?"":request.getHmac(),"UTF-8"));
        parts.add(new StringPart("transferWay",request.getTransferWay() == null ?"":request.getTransferWay(),"UTF-8"));
        parts.add(new StringPart("externalNo",request.getExternalNo() == null ?"":request.getExternalNo(),"UTF-8"));
        return parts.toArray(new Part[parts.size()]);
    }
}
